package cn.zyx.user.controller;

import cn.zyx.basic.util.AjaxResult;
import cn.zyx.user.dto.LoginDto;
import cn.zyx.user.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 登录验证的接口
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    @PostMapping("/account")
    public AjaxResult account(@RequestBody LoginDto loginDto){
        try {
            return loginService.account(loginDto);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙,请稍后重试!");
        }
    }

    /**
     * 微信扫码登录
     * @param params
     * @return
     */
    @PostMapping("/wechat")
    public AjaxResult weChat(@RequestBody Map<String,String> params){
        try {
            return loginService.weChat(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙,请稍后重试!");
        }
    }

    /**
     * 绑定微信用户接口
     * @param params
     * @return
     */
    @PostMapping("/binder/wechat")
    public AjaxResult binder(@RequestBody Map<String,String> params){
        try {
            return loginService.binder(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙,请稍后重试!");
        }
    }
}
